package com.company.modules.project.controller;

import com.company.common.utils.R;
import com.company.modules.project.service.CompanyService;
import com.company.modules.project.entity.Company;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : Real
 * @date : 2022/1/10 17:42
 * @description : Company 控制层
 */
@RestController
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    @RequestMapping(path = "/company/{id}", method = RequestMethod.GET)
    public R getCompanyById(@PathVariable("id") Integer id) {
        if (id == null || id <= 0) {
            return R.error("参数错误");
        }
        // 找到对应的 Company 信息
        Company company = companyService.findCompanyById(id);
        if (company == null) {
            return R.error("参数错误");
        }
        return R.ok().put("data", company);
    }

    @RequestMapping(path = "/company/list", method = RequestMethod.GET)
    public R getCompanyList() {
        List<Company> companyList = companyService.findCompanyList();
        if (companyList != null) {
            return R.ok().put("data", companyList);
        } else {
            return R.error("未知错误，请联系管理员！");
        }
    }


}
